﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Enterprise.Management.Business;

namespace Enterprise.Management.Common
{
    public class FilePathGeneration
    {
        public static string generate(int moduleID, int ctgrID)
        {
            FilePathGenerationBLL bllFilePathGeneration = new FilePathGenerationBLL();

            string folderPath = AppDomain.CurrentDomain.BaseDirectory + "Resources\\";
            string datePath = folderPath + DateTime.Today.Year.ToString() + DateTime.Today.Month.ToString() + "\\";
            string modulePath = datePath + bllFilePathGeneration.getModulePath(moduleID).Mdl_FilePath + "\\";
            string categoryPath = modulePath + bllFilePathGeneration.getCategoryPath(ctgrID).Category_FilePath;

            if (!Directory.Exists(datePath))
            {
                Directory.CreateDirectory(datePath);
                Directory.CreateDirectory(modulePath);
                Directory.CreateDirectory(categoryPath);
                return categoryPath;
            }

            if (!Directory.Exists(modulePath))
            {
                Directory.CreateDirectory(modulePath);
                Directory.CreateDirectory(categoryPath);
                return categoryPath;
            }

            if (!Directory.Exists(categoryPath))
            {
                Directory.CreateDirectory(categoryPath);
                return categoryPath;
            }

            return categoryPath;
        }

        public static string getRefPath(string path)
        {
            int substrLength = path.IndexOf("Resources") + 10;              //"Resources/".Length = 10
            string refPath = path.Substring(substrLength).Replace("\\", "/");
            return refPath;
        }
    }
}